import { post, remove, get, put } from './api'
// import { read } from '../store/modules/init.js'
// 获取角色列表
export const getPerTableApi = (newPer) => {
   const url = '/usermgt/role'
   /*const url = '/usermgt-service-lc/role'*/
    const body = {
        method: 'getRoles',
        args: JSON.stringify(newPer)
    }
    return post(url, body)
}
//获取角色关联人员
export const getRoleTableApi = (id) => {
    const url = '/usermgt/role/' + id
    return get(url)
}
// 修改角色
export const updateRoleApi = (per,id) => {
    const obj = {
        roleName: per.roleName,
        enableStatus: per.enableStatus,
        roleType: per.roleType,
        orgStructId: per.orgStructId,
        comment: per.comment,
        menuCodes: per.menuCodes,
        roleEvents: per.roleEvents
    }
    const body = {
        method: 'updateRole',
        args: JSON.stringify(obj)
    }
    const url = '/usermgt/role/' + id
    return put(url, body)
}
//获取组织架构
export const getOrg_structApi = () => {
    const url = '/usermgt/org_struct'
    return get(url)
}
//
export const addRoleApi = (newPer) => {
    const url = '/usermgt/role'
    /*const url = '/usermgt-service-lc/role'*/
    const body = {
        method: 'addRole',
        args: JSON.stringify(newPer)
    }
    return post(url, body)
}
// 复制角色
export const copyRoleApi = (per) => {
    const obj = {
        roleName: per.roleName,
        enableStatus: per.enableStatus,
        roleType: per.roleType,
        orgStructId: per.orgStructId,
        comment: per.comment,
        menuCodes: per.menuCodes,
        roleEvents: per.roleEvents
    }
    const body = {
        method: 'addRole',
        args: JSON.stringify(obj)
    }
    const url = '/usermgt/role'
    return post(url, body)
}

// 编辑关联人员
export const editpeopleApi = (per,id) => {
    const obj = {
        employeeIds: per.employeeIds
    }
    const body = {
        method: 'associateUser',
        args: JSON.stringify(obj)
    }
    const url = '/usermgt/role/' + id
    return put(url, body)
}
//
export const deletePerApi = (id) => {
    const url = '/usermgt/role/' + id
    return remove(url)
}
//
export const alterPerApi = (per) => {
    const body = {
        method: 'update',
        args: per.args
    }
    const url = '/usermgt/role/' + per.id
    return put(url, body)
}
//
export const getPerInfoApi = (id) => {
    const url = '/usermgt/role/' + id
    return get(url)
}
//
export const getPerMenuApi = () => {
    const url = '/usermgt/menu'
    const body = {
        method:'',
        args: JSON.stringify([ 'menu-logistics-track', 'menu-usermgt', 'menu-logistics-engine'])
    }
    return post(url, body)
}


//编辑关联人员
export const editRelateApi = (newPer,id) => {
    const body = {
        method: 'associateUser',
        args: JSON.stringify({'employeeIds' : newPer})
    }
    const url = '/usermgt/role/' + id
    return put(url, body)
}
//编辑关联人员
export const getRolesByOrgStruct = (args) => {
    const url = '/usermgt/role/'
    const body = {
        method: 'getRolesByOrgStruct',
        args: JSON.stringify(args)
    }
    return post(url, body)
}